<template>
    <div class="order-report-wrapper" style="height: 100%;">
        <div style="background: #fff; height: 100%;">
            <div style="height: 100%">
                <!--         <iframe id="iframe" width="100%" height="100%"  src="http://192.168.84.169/seniorsms/#/company_page1"></iframe>    -->
                <iframe id="iframe" width="100%" height="100%" :src="src"></iframe>
            </div>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">

let iframe = null
let that = null

export default {
    data: function () {
        return {
            activeName: '1',
            token: '',
            hasToken: false,
            hasLoad: false,
            src: ''
        }
    },
    mounted () {
        iframe = window.document.getElementById('iframe')
        iframe.onload = () => {
            that.hasLoad = true
        }
    },
    created () {
        that = this
        // this.src = 'http://localhost:8088/#/'
        // this.src = this.$store.state.SySmsUrl + '/seniorsms/#/'
        this.src = this.$store.state.SySmsUrl + this.page
        console.log(this.src, 'this.src')
		// this.src = 'http://localhost:8088/main_page1#/main_page1'
        this.getToken()
    },
    watch: {
        hasToken () {
            this.postMessage()
        },
        hasLoad () {
            this.postMessage()
        }
    },
    components: {
    },
    props: {
        underLine: null,
        page: String
    },
    computed: {
        userName () {
            return this.$store.state.userName
        }
    },
    methods: {
        postMessage () {
            if (this.hasToken && this.hasLoad) {
                iframe.contentWindow.postMessage({
                    agentName: that.userName,
                    token: that.token,
                    theme: '#409eff',
                    roleId: that.$store.state.roleId,
                    manageRoleType: that.$store.state.manageRoleType,
                    loginToken: localStorage.AuthorizationToken2
                    // agentName: 'lyq1',
                    // token: '03c06f45de3b468f8155d4fd35a1906e',
                    // theme: '#e32c2c'
                    // systemCode: '5'
                }, '*')
            }
        },
        // 换页方法
        getToken () {
            this.$http.post(this.$store.state.IP + '/agent/getAgentSmsToken', {
                data: {
                    agentId: this.$store.state.agentIdFY
                }
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    that.token = response.data.agentToken
                    that.hasToken = true
                }
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
.el-tabs__nav-wrap::after
    content: ''
    position: absolute
    left: 0
    bottom: 0
    width: 100%
    height: 1px
    background-color: #e4e7ed
    z-index: 1

.el-tabs__nav-scroll
    padding: 0 22px

.order-report-wrapper
    width: 100%

    .order-report-wrapper-title
        width: 100%
        height: 40px
        font-size: 14px
        line-height: 30px
        padding-left: 22px
</style>
